package com.snoweagler.verify;

import java.awt.image.BufferedImage;
import java.time.LocalDateTime;

public class ImageCode {

    //验证码图片
    private BufferedImage image;

    //验证码字符
    private String code;

    //过期时间
    private LocalDateTime expireTime;

    /**
     * 图片，验证码，有效时间
     *
     * @param image
     * @param code
     * @param expireIn
     */
    public ImageCode(BufferedImage image, String code, int expireIn) {
        this.image = image;
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
    }

    public ImageCode(BufferedImage image, String code, LocalDateTime expireTime) {
        this.image = image;
        this.code = code;
        this.expireTime = expireTime;
    }

    public BufferedImage getImage() {
        return image;
    }

    public void setImage(BufferedImage image) {
        this.image = image;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }

    //验证码是否还有效
    public Boolean isEffective() {
        return LocalDateTime.now().isBefore(this.expireTime);
    }
}
